package com.hsfw.dbmodule.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by RAZR on 10:36 2018/12/4.
 */
public class UserDetail implements UserDetails {
    private Long id;
    //账号
    private String account;
    //密码
    private String pwd;
    //用户名
    private String userName;
    //邮箱
    private String email;
    //注册时间
    private Timestamp registerTime;
    //用户权限
    private int userJurisdiction;
    //禁言状态
    private int forbiddenSpeechState;
    private String img;
    private String birthday;
    //性别0:保密1:男2:女
    private String sex;
    private String mobile;
    private String qianming;
    private String lastlogintime;
    private String zhuceip;
    private String loginip;
    private String flag;
    private int jifen;
    private int onlinetime;
    private String cookieid;
    //用户类型
    private int type;
    //权限信息
    private Role role;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public UserDetail() {
    }

    public UserDetail(Long id, String account, String pwd, String userName, String email, Timestamp registerTime, int userJurisdiction, int forbiddenSpeechState, String img, String birthday, String sex, String mobile, String qianming, String lastlogintime, String zhuceip, String loginip, String flag, int jifen, int onlinetime, String cookieid, int type, Role role) {
        this.id = id;
        this.account = account;
        this.pwd = pwd;
        this.userName = userName;
        this.email = email;
        this.registerTime = registerTime;
        this.userJurisdiction = userJurisdiction;
        this.forbiddenSpeechState = forbiddenSpeechState;
        this.img = img;
        this.birthday = birthday;
        this.sex = sex;
        this.mobile = mobile;
        this.qianming = qianming;
        this.lastlogintime = lastlogintime;
        this.zhuceip = zhuceip;
        this.loginip = loginip;
        this.flag = flag;
        this.jifen = jifen;
        this.onlinetime = onlinetime;
        this.cookieid = cookieid;
        this.type = type;
        this.role = role;
    }

    public UserDetail(String account, String pwd, String userName, Role role) {
        this.account = account;
        this.pwd = pwd;
        this.userName = userName;
        this.role = role;
    }

    //返回用户权限信息表
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority(role.getRoleCode()));
        return authorities;
    }

    @Override
    public String getPassword() {
        return pwd;
    }

    @Override
    public String getUsername() {
        return account;
    }

    /**
     * 账户是否未过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账户是否未锁定
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码是否未过期
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账户是否激活
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }


    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getQianming() {
        return qianming;
    }

    public void setQianming(String qianming) {
        this.qianming = qianming;
    }

    public String getLastlogintime() {
        return lastlogintime;
    }

    public void setLastlogintime(String lastlogintime) {
        this.lastlogintime = lastlogintime;
    }

    public String getZhuceip() {
        return zhuceip;
    }

    public void setZhuceip(String zhuceip) {
        this.zhuceip = zhuceip;
    }

    public String getLoginip() {
        return loginip;
    }

    public void setLoginip(String loginip) {
        this.loginip = loginip;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public Timestamp getRegisterTime() {
        return registerTime;
    }

    public void setRegisterTime(Timestamp registerTime) {
        this.registerTime = registerTime;
    }

    public int getUserJurisdiction() {
        return userJurisdiction;
    }

    public void setUserJurisdiction(int userJurisdiction) {
        this.userJurisdiction = userJurisdiction;
    }

    public int getForbiddenSpeechState() {
        return forbiddenSpeechState;
    }

    public void setForbiddenSpeechState(int forbiddenSpeechState) {
        this.forbiddenSpeechState = forbiddenSpeechState;
    }

    public int getJifen() {
        return jifen;
    }

    public void setJifen(int jifen) {
        this.jifen = jifen;
    }

    public int getOnlinetime() {
        return onlinetime;
    }

    public void setOnlinetime(int onlinetime) {
        this.onlinetime = onlinetime;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getCookieid() {
        return cookieid;
    }

    public void setCookieid(String cookieid) {
        this.cookieid = cookieid;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }
}
